<?php $connection = mysqli_connect('localhost', 'root', '', '99xu_test') or die('Could not connect to DB'); ?>
<?php
//xac dinh bao nhieu dong
$display = 10;
// tinh tong so trang can hien thi
if (isset($_GET['page']) && (int) $_GET['page']) {
    $page = $_GET['page'];
} else { //neu chua xac dinh, thi tim so trang
    $query = "SELECT COUNT(order_product_id) FROM order_product";
    $res = mysqli_query($connection, $query) or die('Could not select users ' . mysqli_error($connection));
    $rows = mysqli_fetch_array($res, MYSQLI_NUM);
    $record = $rows[0];
    if ($record > $display) {
        $page = ceil($record / $display);
    } else {
        $page = 1;
    }
}

$start = (isset($_GET['start']) && (int) $_GET['start'] >= 0) ? $_GET['start'] : 0;
$sql = "SELECT name
                    FROM order_product
                    ORDER BY name
                    LIMIT $start, $display";
$result = mysqli_query($connection, $sql) or die('Could not select email ' . mysqli_error($connection));
while ($set = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
    $name = $set['name'];
    ?>

    <div id="list_pro1" style="width: 98%;height: 200px;">
        <table width="100%">
            <tr>
                <td width="50%"> <img class="img_np" src="view/image/logo.gif" alt="Sản Phẩm" 
                                       style="border: 2px 1%;border-style: solid;border-color: #3883cc;height: 200px"/> </td>
                <td >
                    <table style=" margin-left: 5%;padding-left: 5%; background-color: #F6F9FF;height: 200px;">
                        <tr>
                            <td colspan="2">
                                <a href="product.php"><?php echo "$name";?></a>
                            </td> 
                        </tr>
                        <tr>
                            <td width="40%">Giá bán:</td>
                            <td width="60%"></td>
                        </tr>
                        <tr>
                            <td width="40%">Phạm vi:</td>
                            <td width="60%"></td>
                        </tr>

                        <tr>
                            <td width="40%">Người bán:</td>
                            <td width="60%"></td>
                        </tr>  
                    </table>
                </td>
            </tr>
        </table>
    </div>
    <?php
}
?>

<ul class="paginate">
    <?php
    if ($page > 1) { //neu can hien thi so trang
        $next = $start + $display;
        $prev = $start - $display;
        $current = ($start / $display) + 1;

        //Hien thi trang Previous
        if ($current != 1) {
            echo "<li><a href='list_pro.php?start=$prev&page=$page'>Previous</a></li>";
        }
        //Hien thi so link
        for ($i = 1; $i <= $page; $i++) {
            if ($current != $i) {
                echo "<li><a href='list_pro.php?start=" . ($display * ($i - 1)) . "&page=$page'>$i</a></li>";
            } else {
                echo "<li class='current'>$i</li>";
            }
        } //End: FOR
        //Hien thi trang Next

        if ($current != $page) {
            echo "<li><a href='list_pro.php?start=$next&page=$page'>Next</a></li>";
        }
    }//End: $page > 1 IF
    ?>
</ul>
<!--
<div id="list_pro2">
        <table width="100%">
        <tr>
            <td width="50%" height="200px"> <img class="img_np" src="" alt="Sản Phẩm" 
                                  style="border: 2px 1%;border-style: solid;border-color: #3883cc"/> </td>
            <td width="50%" >
                <table style="padding-left: 5%; background-color: #F6F9FF;">
                    <tr>
                        <td colspan="2"><a href="product.php">Sản phẩm</a></td>
                    </tr>
                    <tr>
                        <td width="40%">Giá bán:</td>
                        <td width="60%"></td>
                    </tr>
                    <tr>
                        <td width="40%">Phạm vi:</td>
                        <td width="60%"></td>
                    </tr>

                    <tr>
                        <td width="40%">Người bán:</td>
                        <td width="60%"></td>
                    </tr>  
                </table>
            </td>
        </tr>
    </table>
</div>
<div id="list_pro3">
        <table width="100%">
        <tr>
            <td width="50%" height="200px"> <img class="img_np" src="" alt="Sản Phẩm" 
                                  style="border: 2px 1%;border-style: solid;border-color: #3883cc"/> </td>
            <td width="50%" >
                <table style="padding-left: 5%; background-color: #F6F9FF;">
                    <tr>
                        <td colspan="2"><a href="product.php">Sản phẩm</a></td>
                    </tr>
                    <tr>
                        <td width="40%">Giá bán:</td>
                        <td width="60%"></td>
                    </tr>
                    <tr>
                        <td width="40%">Phạm vi:</td>
                        <td width="60%"></td>
                    </tr>

                    <tr>
                        <td width="40%">Người bán:</td>
                        <td width="60%"></td>
                    </tr>  
                </table>
            </td>
        </tr>
    </table>
</div>
<div id="list_pro4">
        <table width="100%">
        <tr>
            <td width="50%" height="200px"> <img class="img_np" src="" alt="Sản Phẩm" 
                                  style="border: 2px 1%;border-style: solid;border-color: #3883cc"/> </td>
            <td width="50%" >
                <table style="padding-left: 5%; background-color: #F6F9FF;">
                    <tr>
                        <td colspan="2"><a href="product.php">Sản phẩm</a></td>
                    </tr>
                    <tr>
                        <td width="40%">Giá bán:</td>
                        <td width="60%"></td>
                    </tr>
                    <tr>
                        <td width="40%">Phạm vi:</td>
                        <td width="60%"></td>
                    </tr>

                    <tr>
                        <td width="40%">Người bán:</td>
                        <td width="60%"></td>
                    </tr>  
                </table>
            </td>
        </tr>
    </table>
</div>
<div id="list_pro5">
        <table width="100%">
        <tr>
            <td width="50%" height="200px"> <img class="img_np" src="" alt="Sản Phẩm" 
                                  style="border: 2px 1%;border-style: solid;border-color: #3883cc"/> </td>
            <td width="50%" >
                <table style="padding-left: 5%; background-color: #F6F9FF;">
                    <tr>
                        <td colspan="2"><a href="product.php">Sản phẩm</a></td>
                    </tr>
                    <tr>
                        <td width="40%">Giá bán:</td>
                        <td width="60%"></td>
                    </tr>
                    <tr>
                        <td width="40%">Phạm vi:</td>
                        <td width="60%"></td>
                    </tr>

                    <tr>
                        <td width="40%">Người bán:</td>
                        <td width="60%"></td>
                    </tr>  
                </table>
            </td>
        </tr>
    </table>
</div>
<div id="list_pro6">
        <table width="100%">
        <tr>
            <td width="50%" height="200px"> <img class="img_np" src="" alt="Sản Phẩm" 
                                  style="border: 2px 1%;border-style: solid;border-color: #3883cc"/> </td>
            <td width="50%" >
                <table style="padding-left: 5%; background-color: #F6F9FF;">
                    <tr>
                        <td colspan="2"><a href="product.php">Sản phẩm</a></td>
                    </tr>
                    <tr>
                        <td width="40%">Giá bán:</td>
                        <td width="60%"></td>
                    </tr>
                    <tr>
                        <td width="40%">Phạm vi:</td>
                        <td width="60%"></td>
                    </tr>

                    <tr>
                        <td width="40%">Người bán:</td>
                        <td width="60%"></td>
                    </tr>  
                </table>
            </td>
        </tr>
    </table>
</div>
<div id="list_pro7">
        <table width="100%">
        <tr>
            <td width="50%" height="200px"> <img class="img_np" src="" alt="Sản Phẩm" 
                                  style="border: 2px 1%;border-style: solid;border-color: #3883cc"/> </td>
            <td width="50%" >
                <table style="padding-left: 5%; background-color: #F6F9FF;">
                    <tr>
                        <td colspan="2"><a href="product.php">Sản phẩm</a></td>
                    </tr>
                    <tr>
                        <td width="40%">Giá bán:</td>
                        <td width="60%"></td>
                    </tr>
                    <tr>
                        <td width="40%">Phạm vi:</td>
                        <td width="60%"></td>
                    </tr>

                    <tr>
                        <td width="40%">Người bán:</td>
                        <td width="60%"></td>
                    </tr>  
                </table>
            </td>
        </tr>
    </table>
</div>
<div id="list_pro8">
        <table width="100%">
        <tr>
            <td width="50%" height="200px"> <img class="img_np" src="" alt="Sản Phẩm" 
                                  style="border: 2px 1%;border-style: solid;border-color: #3883cc"/> </td>
            <td width="50%" >
                <table style="padding-left: 5%; background-color: #F6F9FF;">
                    <tr>
                        <td colspan="2"><a href="product.php">Sản phẩm</a></td>
                    </tr>
                    <tr>
                        <td width="40%">Giá bán:</td>
                        <td width="60%"></td>
                    </tr>
                    <tr>
                        <td width="40%">Phạm vi:</td>
                        <td width="60%"></td>
                    </tr>

                    <tr>
                        <td width="40%">Người bán:</td>
                        <td width="60%"></td>
                    </tr>  
                </table>
            </td>
        </tr>
    </table>
</div>
<div id="list_pro9">
        <table width="100%">
        <tr>
            <td width="50%" height="200px"> <img class="img_np" src="" alt="Sản Phẩm" 
                                  style="border: 2px 1%;border-style: solid;border-color: #3883cc"/> </td>
            <td width="50%" >
                <table style="padding-left: 5%; background-color: #F6F9FF;">
                    <tr>
                        <td colspan="2"><a href="product.php">Sản phẩm</a></td>
                    </tr>
                    <tr>
                        <td width="40%">Giá bán:</td>
                        <td width="60%"></td>
                    </tr>
                    <tr>
                        <td width="40%">Phạm vi:</td>
                        <td width="60%"></td>
                    </tr>

                    <tr>
                        <td width="40%">Người bán:</td>
                        <td width="60%"></td>
                    </tr>  
                </table>
            </td>
        </tr>
    </table>
</div>
<div id="list_pro10">
        <table width="100%">
        <tr>
            <td width="50%" height="200px"> <img class="img_np" src="" alt="Sản Phẩm" 
                                  style="border: 2px 1%;border-style: solid;border-color: #3883cc"/> </td>
            <td width="50%" >
                <table style="padding-left: 5%; background-color: #F6F9FF;">
                    <tr>
                        <td colspan="2"><a href="product.php">Sản phẩm</a></td>
                    </tr>
                    <tr>
                        <td width="40%">Giá bán:</td>
                        <td width="60%"></td>
                    </tr>
                    <tr>
                        <td width="40%">Phạm vi:</td>
                        <td width="60%"></td>
                    </tr>

                    <tr>
                        <td width="40%">Người bán:</td>
                        <td width="60%"></td>
                    </tr>  
                </table>
            </td>
        </tr>
    </table>
</div>
-->